<template>
	<view class="content">
		<view class="box" :style='{"width":"100%","padding":"24rpx","background":"#FFFFFF","height":"100%"}'>
			<view :style='{"width":"100%","padding":"24rpx","display":"block","height":"auto"}'>
				<view style="text-align: center; font-size: 36rpx; font-weight: bold; margin-bottom: 40rpx;">
					密码找回
				</view>
				<view class="forget-input" :style='{"width":"100%","margin":"0 0 24rpx 0","height":"auto"}'>
					<input v-model="username" :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"#000000","background":"none","borderWidth":"0 0 2rpx 0","width":"100%","fontSize":"28rpx","borderStyle":"solid","height":"88rpx"}' type="text" placeholder="请输入您的账号" />
				</view>
                
                <view class="tip-message" :style='{"width":"100%","margin":"20rpx 0 40rpx 0","textAlign":"center","color":"#707070","fontSize":"28rpx"}'>
                    点击"重置密码"按钮后，密码将被重置为：123456
                </view>
                
				<button class="landing" :style='{"border":"0","padding":"0px","margin":"0 0 24rpx 0","color":"#fff","borderRadius":"8rpx","background":"linear-gradient( 135deg, #9EF0EA 0%, #99ABFF 100%)","width":"100%","lineHeight":"80rpx","fontSize":"32rpx","fontWeight":"600","height":"80rpx"}' @tap="resetPassword" type="primary">重置密码</button>
				
				<view class="links" :style='{"width":"100%","margin":"24rpx 0","flexWrap":"wrap","display":"flex","height":"auto"}'>
					<view class="link-highlight" @tap="backLogin" :style='{"color":"#6B6153","padding":"0 8rpx","fontSize":"28rpx"}'>返回登录</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: '',
			}
		},
		onLoad() {
			this.styleChange()
		},
		methods: {
			styleChange() {
				this.$nextTick(()=>{
					// document.querySelectorAll('.forget-input .uni-input-input').forEach(el=>{
					//   el.style.backgroundColor = this.restPwFrom.content.input.backgroundColor
					// })
				})
			},
			backLogin() {
				uni.navigateTo({
					url: '../login/login'
				})
			},
			async resetPassword() {
				if(!this.username) {
					this.$utils.msg('请输入账号')
					return;
                }
                
				try {
					// 调用统一重置密码API
					const res = await this.$api.unifiedResetPass({
						username: this.username
					});
					
					if (res.code === 0) {
						this.$utils.msg(res.msg || '密码已重置为：123456');
						setTimeout(() => {
							uni.navigateTo({
								url: '../login/login'
							});
						}, 1500);
					} else {
						this.$utils.msg(res.msg || '密码重置失败，请检查账号是否存在');
					}
				} catch (e) {
					console.error(e);
					this.$utils.msg('密码重置失败，请检查网络连接');
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: calc(100vh - 44px);
		box-sizing: border-box;
	}
</style>
